package controllers;

import java.util.List;

import com.google.gson.JsonObject;

import models.IdeaDeveloper;
import models.Organization;
import models.OrganizationLead;

import play.mvc.Controller;
import play.mvc.With;

@With(Secure.class)
public class OrganizationLeadFunctionalities extends Controller {

	/**
	 * renders the organization lead view
	 */
	public static void OrganizationLeadView() {
		Long loggedInUserID = Security.userid();
		String loggedInUserName = Security.connected();
		IdeaDeveloper devoloper = IdeaDeveloper.findById(loggedInUserID);
		OrganizationLead organizationlead = OrganizationLead.find(
				"ideaDeveloper =?", devoloper).first();
		List organizations = organizationlead.manages;

		render(loggedInUserID, loggedInUserName, organizations);

	}

	/**
	 * render the profile of the organiztion to be edited by organization lead
	 * 
	 * @author XtarX
	 * @param OrgName
	 */
	public static void editOrganizationProfile(String OrgName) {
		Organization organizaiton = Organization.find("name=?", OrgName)
				.first();
		render(organizaiton);

	}

	/**
	 * edits company's profile information it changes the
	 * description,website,phone of the slected organziation and replaces it
	 * with the edited information
	 *
	 * @author XtarX
	 * @param orgName
	 * the name of the organizaiton to be updated
	 * @param description
	 * the new description of the organization
	 * @param website
	 * the new website of the organization
	 * @param telephone
	 * the new telephone of the organization
	 */
	public static void editCompanyProfile(String orgName, String description,
			String website, String telephone) {
		JsonObject updaateResponse = new JsonObject();
		Organization organiztion = Organization.find("name=?", orgName).first();
		organiztion.description = description;
		organiztion.website = website;
		organiztion.telephone = telephone;
		organiztion.save();
		updaateResponse.addProperty("res", "DONE!");
		renderJSON(updaateResponse.toString());

	}

	/**
	 * renders the external content view
	 */
	public static void externalcontent() {
		render();

	}

}
